package edu.siu.math.egut.functions;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import edu.siu.math.egut.lie.AbstractEgutFunction;
import edu.siu.math.egut.lie.AbstractLiEObject;
import edu.siu.math.egut.lie.LiEText;
import edu.siu.math.egut.lie.LiEType;
import edu.siu.math.egut.lie.NonExceptionalGroupException;
import edu.siu.math.egut.util.ExceptionalGroup;
import edu.siu.math.egut.util.Polynomial;
import edu.siu.math.egut.util.PolynomialReadException;
import edu.siu.math.egut.util.OneParameterSubGroup;
import edu.siu.math.egut.util.ExceptionalGroupElement;

/**
 * A program for use in analyzing the action of one unipotent
 * group on a character of another unipotent group.
 * 
 * @author Joe Hundley
 *
 */
public class  Action extends AbstractEgutFunction {


	
	
	public LiEType[] argList() {
	    LiEType[] result = new LiEType[4];
	    result[0]=LiEType.MAT;
	    result[1]=LiEType.MAT;
	    result[2]=LiEType.TEX;  //actually a polynomial
	    result[3]=LiEType.GRP;
	    return result;
	}//Defines the arguments this function takes


	
	public void run() {

	    AbstractLiEObject[] args;
	    try {
		args = this.getData();
	    } catch (IllegalArgumentException e) {

		e.printStackTrace();
		return;
	    } catch (InstantiationException e) {

		e.printStackTrace();
		return;
	    } catch (IllegalAccessException e) {

		e.printStackTrace();
		return;
	    } catch (InvocationTargetException e) {

		e.printStackTrace();
		return;
	    } catch (NonExceptionalGroupException e) {
		return;
	    } 
	    
	    //Retrieve the arguments from the interpreter
	   
	    int[][] uRoots = (int[][]) (args[0]).getJavaObject();
	    //Parse the first root
	    
	    int[][] dRoots = (int[][]) (args[1]).getJavaObject();
	    //Parse the second root
	    
	    Polynomial psiFactor;
	    
	    try {
		psiFactor = Polynomial.read((String) args[2].getJavaObject());
	    } catch (PolynomialReadException e) {
		System.out.print("Error reading polynomial.");
		return;
	    }
	
	    
	    ExceptionalGroup g = (ExceptionalGroup)(args[3]).getJavaObject();
	    //Parse the group
	    

	    ExceptionalGroupElement d = new ExceptionalGroupElement(g, dRoots, "d");
	    ExceptionalGroupElement u = new ExceptionalGroupElement(g, uRoots, "u");
		
	    this.setData(new LiEText(psiFactor.toString()).toString());
		//format the output as LiE text
			//and	
	    //Pass the data back to the interpreter
			
	    
	}

}
